﻿using System;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using mojoPortal.Web.RS.PRM.AppCode.Lib;

namespace mojoPortal.Web.RS.PRM.Controls
{
    public partial class PropertyHeaderControl : RSBaseUserControl
    {

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public bool LoadPropertyHeader(int companyid, int propertyid)
        {
            bool bHasValue = false;

            if (companyid > 0 && propertyid > 0)
            {
                String strSQL = "EXEC rs_uspGetPropertyHeaderByID @CompanyID, @PropertyID";
                SqlCommand myCommand;
                SqlParameter param;
                SqlConnection myConnection;
                myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[GetRSCompanyConnectionString()].ToString());
                myCommand = new SqlCommand(strSQL, myConnection);
                SqlDataReader myDataReader;

                param = new SqlParameter();
                param.SqlDbType = SqlDbType.Int;
                param.ParameterName = "@CompanyID";
                param.Value = companyid;
                myCommand.Parameters.Add(param);

                param = new SqlParameter();
                param.SqlDbType = SqlDbType.Int;
                param.ParameterName = "@PropertyID";
                param.Value = propertyid;
                myCommand.Parameters.Add(param);


                myConnection.Open();
                myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
                if (myDataReader.HasRows)
                {
                    myDataReader.Read();
                    //Header Info
                    lblSubdivisionName.Text = myDataReader["SubdivisionName"].ToString();
                    lblHouseholdIncome.Text = myDataReader["HouseholdIncome"].ToString();
                    lblPropertyType.Text = myDataReader["PropertyType"].ToString();
                    lblPropertyLocation.Text = myDataReader["PropertyLocation"].ToString();

                    lblManagerName.Text = myDataReader["ManagerName"].ToString();
                    lblOwnerName.Text = myDataReader["PropertyOwner"].ToString();
                    lblTenantName.Text = myDataReader["CurrentTenant"].ToString();
                    lblLeaseStatus.Text = myDataReader["CurrentLeaseStatus"].ToString();

                    lblHOAFee.Text = myDataReader["hoafee"].ToString();
                    lblHOATerm.Text = myDataReader["hoaterm"].ToString();

                    if (myDataReader["CreateDate"] != DBNull.Value)
                    {
                        DateTime createdt = Convert.ToDateTime(myDataReader["CreateDate"].ToString());
                        lblCreateDate.Text = createdt.ToShortDateString();
                    }
                }
            }
            return bHasValue;

        }
    }
}